<%= page_title do %>
  Secret History <%= link_to params[:id], secret_path(params[:id]) %>
<% end %>

<section class="clearfix tabs">
  <div class="table table-hover table-condensed">
    <table class="table">
      <tr><th colspan="2">Details</th></tr>
      <% @history.except(:versions).each do |attribute, value| %>
        <tr>
          <td><%= attribute %></td>
          <td><%= value %></td>
        </tr>
      <% end %>

      <% @history.fetch(:versions).sort_by { |v, _| Integer(v.to_s) }.reverse_each do |version, data| %>
        <tr>
          <th colspan="2">
            Version <%= version %>
            <% if version.to_s == @history[:current_version].to_s %>
              Current
            <% else %>
              <%= link_to "Revert", revert_secret_path(params[:id], version: version), data: {method: :post}, title: "Revert to this version"%>
            <% end %>
          </th>
        </tr>
        <% data.reject { |_, v| v.nil? }.each do |attribute, value| %>
          <tr>
            <td><%= attribute %></td>
            <td><%= render_secret_attribute(attribute, value) %></td>
          </tr>
        <% end %>
      <% end %>
    </table>
  </div>
</section>
